home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple Developer Connection Student Program
/
ADC Tools Sampler CD Disk 3 1999.iso
/
Documentation
/
Books
/
Learn Java on the Macintosh
/
Learn Java Projects
/
13.02 - constructor
/
Constructor.java
< prev
next >
Wrap
Text File
|
1996-04-22
|
983b
|
48 lines
/* -------------------------------------------------------------
This applet creates circles using different constructors.
Java's classes: Applet (applet)
System (lang)
Custom classes: Constructor
Circle
------------------------------------------------------------- */
import java.applet.Applet;
public class Constructor extends Applet {
public void init() {
Circle c1, c2, c3;
c1 = new Circle();
c2 = new Circle(20);
c3 = new Circle(c2);
c1.displayInfo();
c2.displayInfo();
c3.displayInfo();
}
}
class Circle {
static int defaultRadius = 10;
int radius;
Circle() {
radius = defaultRadius;
}
Circle(int radius) {
this.radius = radius;
}
Circle(Circle referenceCircle) {
this.radius = referenceCircle.radius;
}
void displayInfo() {
System.out.println("This circle's radius is " + radius);
}
}